package org.aplombh.java.leetcode.all;

public class _27移除元素 {
    public static void main(String[] args) {
        System.out.println(new Solution27_1().removeElement(new int[]{0,1,2,2,3,0,4,2}, 2));
    }
}

class Solution27_1 {
    public int removeElement(int[] nums, int val) {

        if (nums == null)
            return 0;

        int i = 0, len = 0;

        while (i < nums.length) {

            if (len != i) {
                nums[len] = nums[i];
            }

            if (nums[i] != val) {
                len++;
            }

            i++;

        }
        return len;
    }
}